package com.kuaixueit.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.kuaixueit.crm.common.ResultVO;
import com.kuaixueit.crm.pojo.CPosition;
import com.kuaixueit.crm.service.PositionService;

@Controller
@RequestMapping("posd")
public class PositionController {
  //注入service
  @Autowired
  private PositionService positionService;
  
  @RequestMapping("select")
  @ResponseBody
  public ResultVO list(@RequestParam(defaultValue = "1")Integer page ,@RequestParam(defaultValue = "10")Integer rows,String positionName){
    PageInfo info = new PageInfo();
    try {
     info = positionService.getPosition(page, rows ,positionName);
    } catch (Exception e) {
      e.printStackTrace();
      return new ResultVO(null,null,false,"服务器内部错误，请联系管理员");
    }
    return new ResultVO(info.getTotal(), info.getList(), true, "查询成功");
  }
  //添加部门职位
  @RequestMapping("add")
  @ResponseBody
  public ResultVO add(CPosition position){
    position.setId(null);
    try {
      Integer i = positionService.addPosition(position);
    } catch (Exception e) {
      e.printStackTrace();
      return new ResultVO(null,null,false,"服务器内部错误，请联系管理员");
    }
    return new ResultVO(null, null, true, "添加成功");
    
  }
  //修改部门
  @RequestMapping("update")
  @ResponseBody
  public ResultVO update(CPosition position){
      try {
        Integer i = positionService.update(position);
      } catch (Exception e) {
        e.printStackTrace();
        return new ResultVO(0L,null,false,"服务器内部错误，请联系管理员");
      }
      return new ResultVO(0L, null, true, "修改成功");
    
  }
  //删除部门
  @RequestMapping("delete")
  @ResponseBody
  public ResultVO delete(Integer id){
    try {
      Integer i = positionService.delete(id);
    } catch (Exception e) {
      e.printStackTrace();
      return new ResultVO(0L,null,false,"服务器内部错误，请联系管理员");
    }
    return new ResultVO(0L, null, true, "删除成功");
    
  }
  
}
